package n2386;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	
	static int N,M;
	
	static int a[][]=new int[101][101];
	
	static boolean v[][]=new boolean[101][101];
	
	static int count;
	static boolean solve(int i,int j)
	{
			if(i<0||j<0||i>=N||j>=M||v[i][j]||a[i][j]==0)return false;
			v[i][j]=true;
			solve(i-1,j-1);
			solve(i-1,j);
			solve(i-1,j+1);
			solve(i,j+1);
			solve(i+1,j+1);
			solve(i+1,j);
			solve(i+1,j-1);
			solve(i,j-1);
			return true;
	}
	
	
	/**
	 * @param args
	 */
	public static void main(String[] args)  throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(bf.readLine());
		N=Integer.parseInt(st.nextToken());
		M=Integer.parseInt(st.nextToken());
		for(int i=0;i<N;i++)
		{
			char c[]=bf.readLine().toCharArray();
			for(int j=0;j<M;j++)
			{
				if(c[j]=='W')a[i][j]=1;
				else a[i][j]=0;
			}
		}
		
		for(int i=0;i<N;i++)
			for(int j=0;j<M;j++)
			{
				if(solve(i,j))count++;
			}
		
		System.out.println(count);
	}

}
